package com.ruoyi.slideshow.user.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.slideshow.domain.NexusSlideshow;
import com.ruoyi.slideshow.service.INexusSlideshowService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 轮播图Controller
 *
 * @author Afanda
 * @date 2025-04-15
 */
@RestController
@Slf4j
@RequestMapping("/User/NexusSphere/slideshow")
public class NexusSlideshowUserController extends BaseController {
    @Autowired
    private INexusSlideshowService nexusSlideshowService;

    @Autowired
    private RedisCache redisCache;

    private static final String USER_SLIDESHOW_KEY = "slideshow";

    @GetMapping("/list")
    public AjaxResult selectNexusSlideshowVoList() {
        log.info("获取所有的轮播图数据");

        List<NexusSlideshow> nexusSlideshows = null;
        String key = USER_SLIDESHOW_KEY;
        Object cacheObject = redisCache.getCacheObject(key);
        if(cacheObject == null){
            log.info("获取所有的轮播图数据,缓存中不存在数据");
            nexusSlideshows = nexusSlideshowService.selectNexusSlideshowVoList();
            redisCache.setCacheObject(key,nexusSlideshows);
        }else{
            nexusSlideshows = (List<NexusSlideshow>) cacheObject;
            log.info("获取所有的轮播图数据,缓存中存在数据:{}",nexusSlideshows);
        }
        return AjaxResult.success(nexusSlideshows);
    }
}
